#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int N, K, score, numofPlayers;
string number;
struct player
{
    string regNumber;
    int finalRank;
    int locationNumber;
    int localRank;
    int score;
    player(string rn = "", int score = -1, int ln = -1, int fr = -1, int lr = -1)
        : regNumber(rn), finalRank(fr), localRank(lr), locationNumber(ln), score(score){};
    bool operator<(player p)
    {
        if (score == p.score)
            return regNumber < p.regNumber;
        else
            return score > p.score;
    }
};
vector<vector<player>> players;
int main()
{
    cin >> N;
    players.resize(N + 1);
    for (int i = 1; i <= N; ++i)
    {
        cin >> K;
        numofPlayers += K;
        for (int j = 1; j <= K; ++j)
        {
            cin >> number >> score;
            player p = player(number, score, i);
            players[i].push_back(p);
        }
        sort(players[i].begin(), players[i].end());
        for (int j = 0, rank = 0, prescore = 101, sameNum = 0; j < players[i].size(); ++j)
        {
            if (players[i][j].score < prescore)
                rank++, prescore = players[i][j].score, rank += sameNum, sameNum = 0;
            else
                sameNum++;
            players[i][j].localRank = rank;
        }
    }
    cout << numofPlayers;
    for (int i = 0, rank = 0, prescore = 101, sameNum = 0; i < numofPlayers; ++i)
    {
        player p;
        int u = -1;
        for (int k = 1; k <= N; ++k)
        {
            if (players[k].empty())
                continue;
            if (players[k].front() < p)
            {
                p = players[k].front();
                u = k;
            }
        }
        if (u == -1)
            break;
        players[u].erase(players[u].begin());
        if (p.score < prescore)
            rank++, prescore = p.score, rank += sameNum, sameNum = 0;
        else
            sameNum++;
        p.finalRank = rank;
        cout << endl
             << p.regNumber << " " << p.finalRank << " " << p.locationNumber << " " << p.localRank;
    }
    return 0;
}